<?php
use common\extended\system\Util;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>
<style>
    .layui-layer-btn{text-align: center;}

</style>
<div class="row">
    <div class="container lh30">
        <a class="topNav" href="<?= Url::toRoute('/system/site/index') ?>" style=""><img
                src="<?= Yii::getAlias('@web/backend/img/home/home.png'); ?>" alt="首页"/>返回首页</a>
    </div>
</div>

<div class="row nav-brand-bg borB">
    <div class="container lh30">
        <ul class="nav nav-tabs">
            <li class="active"><a href="javascript:;">员工列表</a></li>
        </ul>
    </div>
</div>

<div class="container">
    <div class="lh45 clearfix mg20-y">
        <div class="pull-left">
            <a class="add btnBg" durl="<?= Url::toRoute('employee/add') ?>" style="cursor: pointer;">增加员工</a>
        </div>
        <div class="pull-right">
            <input type="hidden" name="starttime" />
            <input type="hidden" name="endtime" />
            <form method="get" class="form-inline" id="search-form">
                <div class="tab-left">
                    <a  href="?filter_date=<?= Util::getMonth(date('Y-m-d', time())); ?>" <?php if ($filterDate == Util::getMonth(date('Y-m-d', time()))):?> class="current" <?php endif; ?>>本月</a>
                    <a  href="?filter_date=<?= Util::getWeek(date('Y-m-d', time())); ?>" <?php if ($filterDate == Util::getWeek(date('Y-m-d', time()))): ?>  class="current" <?php endif; ?>>本周</a>
                </div>
                <div class="form-group" style="float:right;">
                    <label class="control-label" for="employee_time">时间:</label>
                    <input id="starttime" type="text" style="width:155px;border-radius: 3px;"  class="laydate-icon lh45" />
                    <label class="control-label" for="employee_time">至</label>
                    <input id="endtime" type="text" style="width:155px;border-radius: 3px;"   class="laydate-icon lh45" />
                    <input  name="filter_date" type="hidden" value="<?=$filterDate?>"/>
                    <span class="btnMd" style=" color: #fff;border-radius: 6px; ">
			            <input type="submit" value="搜索" style="display: block; width: 100%; background: 0; border:0; line-height: 42px;">
		            </span>
                </div>
            </form>
        </div>
    </div>

    <?php if(empty($list)){?>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>员工</th>
            <th>电话</th>
            <th>销售业绩</th>
            <th>消耗业绩</th>
            <th>手工提成</th>
            <th>合作项目业绩</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td colspan="7" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
        </tr>
        </tbody>
    </table>
    <?php }else{?>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>员工</th>
            <th>电话</th>
            <th>销售业绩</th>
            <th>消耗业绩</th>
            <th>手工提成</th>
            <th>合作项目业绩</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($list as $r): ?>
            <?php ActiveForm::begin(['action' => Url::toRoute('employee/update'),'options'=>['name'=>'myform']])?>
            <tr>
                <td><input class="repertory_name read-only staff_name" type="text" name="staff_name" value="<?= Html::encode($r['employee_name']) ?>" readonly/></td>
                <td><input class="read-only staff_mobile" type="text" name="staff_mobile" value="<?= Html::encode($r['employee_mobile']) ?>" readonly/></td>
                <td><?= Html::defaultval($r['sell_count'], '0.00') ?></td>
                <td><?= Html::defaultval($r['consume_count'], '0.00') ?></td>
                <td><?= Html::defaultval($r['handwork_count'], '0.00') ?></td>
                <td><?= Html::defaultval($r['epiboly_count'], '0.00') ?><input type='hidden' name='id' value='<?= $r['employee_id'] ?>'></td>
                <td width="182">
                    <a durl="<?= Url::toRoute(['employee/changestate','id'=>$r['employee_id']]) ?>" class="editBtn del btn btn-sm btn-borB">员工离职</a>
                    <div class="fadeBox" style="display: none">
                        <input type="submit" onclick="return check()"  class="edit btn btn-sm btn-borB4" value="保存"/>
                        <a href="#" class="edit rest btn btn-sm btn-borB4 ml20">取消</a>
                    </div>
                </td>
            </tr>
            <?php ActiveForm::end(); ?>
        <?php endforeach; ?>
        </tbody>
    </table>
    <?php }?>
    <div class="page">
        <?= LinkPager::widget([
            'pagination' => $page,
            'firstPageLabel' => '首页',
            'nextPageLabel' => '下一页',
            'prevPageLabel' => '上一页',
            'lastPageLabel' => '末页',
            'hideOnSinglePage' => false
        ]); ?>
    </div>
</div>


<?php $this->beginBlock('js_index_end') ?>
var thismonth = "<?php if ($filterDate=='') echo Util::getMonth(date('Y-m-d', time())); ?>";
    function check(){
        var $username = document.getElementsByClassName('staff_name')
        var $tel = document.getElementsByClassName('staff_mobile')
        var pattern= /^1[358]\d{9}$/
         for (var i=0;i<$username.length;i++) {
            var $key = $username[i]
            console.log($key.value)
            if ($key.value == 0) {
                layer.msg('姓名填写不完整', {
                icon: 2,
                shade: 0.2,
            });
            return false
            }
            else if ($key.value.length > 5) {
                layer.msg('请输入小于5个字符的内容', {
                icon: 2,
                shade: 0.2,
            });
            return false
            }
         };

        for (var i=0;i<$tel.length;i++) {
            var $phone = $tel[i]
            console.log($phone.value)
            if( $phone.value!='' && !pattern.test($phone.value) ) {
                layer.msg('请输入有效的手机号码！', {
                    icon: 2,
                });
                $phone.value="";
             return false;
            }
        }
    }
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index_end'], $this::POS_END); ?>

<?php
$session = Yii::$app->getSession();
if ($session->hasFlash('success')) {
echo "layer.alert('" . $session->getFlash('success') . "', {icon:1})";
}
?>
<?php $this->registerJsFile("@web/system/employee/list.js", ['position' => $this::POS_END]); ?>
